﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Utils.Ini
{
    public class IniUtil
    {
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);


        /// <summary>
        /// 从Ini文件获取数据12
        /// </summary>
        /// <param name="section">应用程序</param>
        /// <param name="key">键的名称</param>
        /// <returns>键的值</returns>
        public static string GetPrivateProfileString(string section, string key, string iniFilename)
        {
            int nCapacity = 1024;
            StringBuilder temp = new StringBuilder(nCapacity);
            string path = Environment.CurrentDirectory + @"\" + iniFilename;
            int i = GetPrivateProfileString(section, key, "", temp, nCapacity, path);
            return temp.ToString();
        }
    }
}
